var o, e = require, t = module, n = exports, i = this && this.__extends || (o = function(e, t) {
    return (o = Object.setPrototypeOf || {
        __proto__: []
    } instanceof Array && function(e, t) {
        e.__proto__ = t;
    } || function(e, t) {
        for (var n in t) t.hasOwnProperty(n) && (e[n] = t[n]);
    })(e, t);
}, function(e, t) {
    function n() {
        this.constructor = e;
    }
    o(e, t), e.prototype = null === t ? Object.create(t) : (n.prototype = t.prototype, 
    new n());
}), a = this && this.__decorate || function(e, t, n, o) {
    var r, i = arguments.length, a = i < 3 ? t : null === o ? o = Object.getOwnPropertyDescriptor(t, n) : o;
    if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) a = Reflect.decorate(e, t, n, o); else for (var c = e.length - 1; 0 <= c; c--) (r = e[c]) && (a = (i < 3 ? r(a) : 3 < i ? r(t, n, a) : r(t, n)) || a);
    return 3 < i && a && Object.defineProperty(t, n, a), a;
};

Object.defineProperty(n, "__esModule", {
    value: !0
});

var r = e("GameConfig"), s = e("LoadManager"), c = e("VideoRewardItemView"), l = cc._decorator, d = l.ccclass, u = l.property, p = function(t) {
    function e() {
        var e = null !== t && t.apply(this, arguments) || this;
        return e.userSprite = null, e.nameLabel = null, e.rankLabel = null, e.layout = null, 
        e.itemPrefab = null, e.items = [], e.data = null, e.__itemID = null, e;
    }
    return i(e, t), e.prototype.start = function() {}, e.prototype.init = function(t) {
        var n = this;
        if (null == (this.data = t).rank || isNaN(t.rank) || (this.rankLabel.string = t.rank.toString()), 
        t.nickname && (5 < t.nickname.length ? this.nameLabel.string = t.nickname.substring(0, 5) + "..." : this.nameLabel.string = t.nickname), 
        null != t.rank && !isNaN(t.rank)) {
            var o = 0;
            if (r.GC.videoRewardConfig.forEach(function(e) {
                t.rank >= e.rank && (o = e.mode);
            }), o < r.GC.videoModeConfig.length) {
                var i = r.GC.videoModeConfig[o];
                if (this.items = this.layout.getComponentsInChildren(c.default), this.items.forEach(function(e, t) {
                    t < i.length && e.init(i[t]);
                }), this.items.length < i.length) for (;this.items.length < i.length; ) {
                    var e = cc.instantiate(this.itemPrefab);
                    e.parent = this.layout;
                    e = e.getComponent(c.default);
                    this.items.push(e), e.init(i[this.items.length - 1]);
                } else for (;this.items.length > i.length; ) this.layout.removeChild(this.items.pop().node);
            }
        }
        t.headicon && s.default.getInstance().loadImage({
            url: t.headicon
        }).then(function(e) {
            n.userSprite && e instanceof cc.Texture2D ? n.userSprite.spriteFrame = new cc.SpriteFrame(e) : cc.log(e);
        }).catch(function(e) {
            console.error(e);
        });
    }, a([ u(cc.Sprite) ], e.prototype, "userSprite", void 0), a([ u(cc.Label) ], e.prototype, "nameLabel", void 0), 
    a([ u(cc.Label) ], e.prototype, "rankLabel", void 0), a([ u(cc.Node) ], e.prototype, "layout", void 0), 
    a([ u(cc.Prefab) ], e.prototype, "itemPrefab", void 0), a([ d ], e);
}(cc.Component);

n.default = p;